/*
 * FileName: ExecutionProcessParameterTableModel.java
 * Created on: 
 */
package co.edu.uniandes.intercon.client.model;

import javax.swing.table.AbstractTableModel;

import co.edu.uniandes.intercon.core.model.ApplicationDto;
import co.edu.uniandes.intercon.core.model.BaseDto;
import co.edu.uniandes.intercon.core.model.EDataType;
import co.edu.uniandes.intercon.core.model.ParamDto;

/**
 * <code>TableModel</code> used to represent the parameters used by a process
 * 
 * @author Fabian Gutierrez [fagossa@gmail.com]
 */
public class ExecutionProcessParameterTableModel extends ProcessParameterTableModel {
		
	/**
	 * Serial version of the class
	 */
	private static final long serialVersionUID = -343852961476152959L;
	
	/**
	 * Titles used in the table
	 */
	private String[] titles = {"Nombre", DATA_TYPE, "Valor"};
	
	 /**
     * @see AbstractTableModel#getColumnName
     */
    @Override
    public String getColumnName(int column) {
        return titles[column];
    }
	
	/**
     * @see AbstractTableModel#getColumnCount
     */
    public int getColumnCount() {
        return titles.length;
    }
    
    /**
     * @see BaseP2PApplicationTableModel#getValueAt(int, ApplicationDto)
     */
    @Override
    public Object getValueAt(int columnIndex, BaseDto dtoBase) {
    	ParamDto dto = (ParamDto)dtoBase;
    	Object resultado = "";
		if(columnIndex==0) {
			resultado = dto.getName();
		}
		if(columnIndex==1) {
			resultado = dto.getDataType();
		}
	
		if(columnIndex==2) {
			resultado = dto.getValue();
		}
	
		return resultado;
    }
    
    /**
     * @see BaseP2PApplicationTableModel#setValueAt(int, ApplicationDto)
     */
    @Override
	public void setValueAt(Object obj, int row, int columnIndex) {
		ParamDto paramDto = (ParamDto)getRecord(row);
		if(columnIndex==0) {
			paramDto.setName((String)obj);
		} else if(columnIndex==1) {
			paramDto.setDataType((EDataType)obj);
		} else if(columnIndex==2) {
			paramDto.setValue((String)obj);
		}
	}

	@Override
	public boolean isCellEditable(int row, int column) {
		return column==2;
	}

}
